const express = require("express");

const bodyParser = require("body-parser");
const cors = require("cors");
const db = require("./db/index")
const students = require("./router/students");
const users = require("./router/users");
const exam = require("./router/exam");
const app = express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended:true}));
app.use(cors());

app.use("/",async(req,res,next)=>{
    try{
        await db;
        next();
    }catch(e){
        console.log(e);
        res.send("服务器和数据库连接失败")
    }
})
app.use(users);
app.use(students);
app.use(exam);
app.listen(3000,(err)=>{
    if(!err) console.log("服务器启动成功！！！");
    else console.log(err);
})